package com.c6;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/firstServlet")
public class FirstSeivlet  extends HttpServlet {
    public FirstSeivlet(){
        //无参构造方法
        super();//执行父类的构造方法
    }
    @Override //重载修饰符 覆盖父类方法
    public void destroy(){//销毁方法
        super.destroy();
    }
    @Override
    public void init() throws ServletException{
        //当初始化失败时 抛出servlet的异常
        super.init();
    }
    protected void dopost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        //返回一个PrintWriter对象，Servlet使用它来输出字符串形式的正文数据
        //以下为输出的HTML正文数据
        out.println("!DOCTYPE HTML PUBLIC\"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        out.println("<HTML>");
        out.println("head");
        out.println("<title>动态生成的HTML文档<title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<table border=1 align=center>");
        out.println("<tr>");
        out.println("<td>动态生成HTML文档");
        out.println("<td>");
        out.println("/<tr>");
        out.println("</table>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
        doPost(request,response);
    }
}
